<!DOCTYPE html>
<html>
#{include file="header.html"}#
<style>
</style>

<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">

			<div class="col-md-2">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>计划任务</h5>
					</div>
					<div class="list-group">
						<a href="#" class="list-group-item active" data-search="1">今日未执行</a>
						<a href="#" class="list-group-item" data-search="5">今日已执行</a>
						<a href="#" class="list-group-item" data-search="2">未来七天</a>
						<hr color="#ccc" style="margin: 0;" />
						<a href="#" class="list-group-item" data-search="3">已过期</a>
						<a href="#" class="list-group-item" data-search="4">已执行</a>
					</div>
				</div>
			</div>

			<div class="col-sm-10">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>待办事项</h5>
						<div class="ibox-tools">
							<a href="?">
								<button type="button" class="btn btn-xs"><i class="fa fa-refresh"></i>刷新</button>
							</a>
						</div>
					</div>
					<div class="ibox-content table-responsive">
						<div class="row">
							<!-- 表单 -->
							<form id="pagerForm" method="post" class="form-inline">
								<div class="col-sm-3 m-b-xs">
									<a class="btn btn-info single_operation" data-act="add" href="javascript:void(0)"><i
											class="fa fa-plus"></i>添加</a>
									<div class="btn-group">
										<button data-toggle="dropdown" class="btn btn-default dropdown-toggle">批量操作
											<span class="caret"></span></button>
										<ul class="dropdown-menu">
											<li><a href="javascript:void(0)" class="batch_operation"
													data-act="online">批量发短信</a></li>
											<li><a href="javascript:void(0)" class="batch_operation"
													data-act="offline">批量发邮件</a></li>
											<li class="divider"></li>
											<li><a href="javascript:void(0)" class="batch_operation"
													data-act="del">批量删除</a></li>
										</ul>
									</div>
								</div>
								<div class="col-sm-9 m-b-xs text-right">

									<!-- <div class="form-group text-left">
										<select data-placeholder="选择沟通阶段" name="salestage"
											class="chosen-select salestage-chosen-select" style="width: 150px;"
											tabindex="2">
											<option value="">所有沟通阶段</option>
											#{foreach from=$salestage key=k item=v}#
											<option value="#{$v.dict_id}#" hassubinfo="true">#{$v.name}#</option>
											#{/foreach}#
										</select>
									</div> -->

									<div class="input-group pd-b-5">
										<input type="text" name="intro" placeholder="输入内容搜索" class="form-control">
									</div>
									<div class="input-group pd-b-5">
										<input type="text" name="customer_name" placeholder="输入客户名称搜索"
											class="form-control">
									</div>
									<input id="input_search" type="hidden" name="left_search" value="1">
									<div class="input-group">
										<span class="input-group-btn">
											<button type="button" class="btn btn-primary ajaxSearchForm">
												<i class="fa fa-search"></i> 搜索</button>
										</span> </div>
								</div>
							</form>

						</div>
						<table class="table table-hover sorttable 07fly-table" width="100%">
							<thead>
								<tr>
									<th width="22"><input type="checkbox" group="ids" class="checkboxCtrl"></th>
									<th width="200" orderField="by_customer" class="sort-filed"><span>客户名称</span></th>
									<th width="150" orderField="by_conntime" class="sort-filed"><span>最近联系时间</span></th>
									<th><span>沟通内容</span></th>
									<th width="150" orderField="by_nexttime" class="sort-filed"><span>下次联系时间</span></th>
									<th width="80"><span>沟通方式</span></th>
									<th width="80"><span>当前阶段</span></th>
									<th width="80">操作</th>
								</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
						<table class="table 07fly-table">
							<tfoot class="ibox-content">
								<tr>
									<td align="center" class="pagestring"></td>
								</tr>
							</tfoot>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>

</html>
<script id="tableListTpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><input name="trace_id" class="checkboxCtrlId" value="<%=list[i]['trace_id']%>" type="checkbox"></td>
		<td><%=list[i]['customer_name']%><br><small>(代表：<%=list[i]['linkman']['name']%>)</small></td>
		<td><%=list[i]['conn_time']%></td>
		<td class="overflow-td"><%=list[i]['intro']%></td>	
		<td><%=list[i]['next_time']%></td>
		<td><%=list[i]['salemode_name']%></td>
		<td><%=list[i]['salestage_name']%></td>	
		<td width='10'>
			<div class="btn-group">
				<button data-toggle="dropdown" class="btn btn-default dropdown-toggle">操作 <span class="caret"></span></button>
				<ul class="dropdown-menu">
					<li>
						<a href="javascript:void(0)" class="alert_content" data-id="<%=list[i]['trace_id']%>">查看内容</a>
					</li>
					<li>
						<a href="javascript:void(0)" class="single_operation" data-id="<%=list[i]['trace_id']%>" data-act="modify">修改</a>
					</li>
					<li>
						<a href="javascript:void(0)" class="single_operation" data-id="<%=list[i]['trace_id']%>" data-act="del">删除</a>
					</li>
				</ul>
			</div>
		</td>
	</tr>
<% } %>
</script>
<script src="#{$smarty.const.APP}#/View/template/js/content.js?v=1.0.0"></script>
<script type="text/javascript">
	var ajaxUrl = '#{$smarty.const.ACT}#/plan/Wait/cst_trace_json/';
	$(document).ready(function () {
		/* CSS控制 */
		$(".list-group-item").css({ "border": "none" });
		$(".list-group-item").click(function () {
			$(".list-group-item").removeClass("active animated fadeIn");
			$(this).addClass("active animated fadeIn");
			var search_value = $(this).data("search");
			$("#input_search").val(search_value);
			ajaxSearchFormData = $("form").serialize();
			turnPage(1);
		});

		//弹窗内容
		$("body").on("click", ".alert_content", function () {
			var cont = $(this).parents('tr:first').children('.overflow-td').html();
			trace_id = $(this).attr("data-id");
			layer.open({
				title: '内容',
				content: cont,
				btn: ['标记执行', '取消'] //可以无限个按钮
				, yes: function () {

					$.ajax({
						type: "POST",
						url: "#{$smarty.const.ACT}#/plan/Wait/cst_trace_flag/",
						data: { "trace_id": trace_id },
						dataType: "json",
						success: function (data) {
							if (data.statusCode == '200') {
								layer.msg('操作成功', { icon: 1 });
							}else{
								layer.msg('失败', { icon: 2 });
							}
						}
					});
				}
				, cancel: function () {

				}
			});
		});



		turnPage(1);//页面加载时初始化分页
		$('.chosen-select').chosen({ search_contains: true });
		$('.chosen-select').chosen().change(function () {
			ajaxSearchFormData = $("form").serialize();
			turnPage(1);
		});
		//添加
		$("body").on("click", ".cst_trace_add", function () {
			layer.open({
				type: 2,
				title: '添加跟踪记录',
				shadeClose: true,
				fixed: false, //不固定
				area: ['90%', '90%'],
				content: '#{$smarty.const.ACT}#/crm/CstTrace/cst_trace_add/' //iframe的url
			});
			return false;
		});

		$("body").on("click", ".batch_operation", function () {
			batch_act = $(this).attr("data-act")
			var chk_value = [];
			$("tbody input[class='checkboxCtrlId']:checked").each(function () {
				chk_value.push($(this).val());
			});
			trace_id_txt = chk_value.join(",");
			if (batch_act == "recommend") {
				act_url = "#{$smarty.const.ACT}#/crm/CstTrace/cst_trace_modify_recommend/";
			} else if (batch_act == "del") {
				act_url = "#{$smarty.const.ACT}#/crm/CstTrace/cst_trace_del/";
			}
			//alert(chk_value.length==0 ?'你还没有选择任何内容！':chk_value); 
			$.ajax({
				type: "POST",
				url: act_url,
				data: { "trace_id": trace_id_txt },
				dataType: "json",
				success: function (data) {
					if (data.statusCode == '200') {
						layer.msg('操作成功', { icon: 1 });
						turnPage(1);
					}
				},
				complete: function () {//完成响应
				}
			});
		});

		$("body").on("click", ".single_operation", function () {
			trace_id = $(this).attr("data-id");
			single_act = $(this).attr("data-act")
			if (single_act == "add") {
				layer.open({
					type: 2,
					title: '添加跟踪记录',
					shadeClose: true,
					fixed: false, //不固定
					area: ['90%', '90%'],
					content: '#{$smarty.const.ACT}#/crm/CstTrace/cst_trace_add/',
					end: function () {
						turnPage(1);//页面加载时初始化分页
					}
				});
				return false;
			} else if (single_act == "modify") {
				layer.open({
					type: 2,
					title: '修改跟踪记录',
					shadeClose: true,
					fixed: false, //不固定
					area: ['90%', '90%'],
					content: '#{$smarty.const.ACT}#/crm/CstTrace/cst_trace_modify/trace_id/' + trace_id + '/',
					end: function () {
						turnPage(1);//页面加载时初始化分页
					}
				});
				return false;
			} else if (single_act == "del") {
				act_url = "#{$smarty.const.ACT}#/crm/CstTrace/cst_trace_del/";
			}
			$.ajax({
				type: "POST",
				url: act_url,
				data: { "trace_id": trace_id },
				dataType: "json",
				success: function (data) {
					if (data.statusCode == '200') {
						layer.msg('操作成功', { icon: 1 });
					}
				}
			});
		});


	});
</script>